package br.progweb.webapp.service.impl;

import br.progweb.webapp.dao.ContatoDao;
import br.progweb.webapp.model.Contato;
import br.progweb.webapp.service.ContatoManager;
import org.appfuse.service.impl.GenericManagerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: luiza
 * Date: 05/09/12
 * Time: 00:47
 * To change this template use File | Settings | File Templates.
 */
@Service("contatoManager")
public class ContatoManagerImpl extends GenericManagerImpl<Contato, Long> implements ContatoManager {
// ------------------------------ FIELDS ------------------------------

    ContatoDao contatoDao;

// --------------------------- CONSTRUCTORS ---------------------------

    @Autowired
    public ContatoManagerImpl(ContatoDao contatoDao) {
        super(contatoDao);
        this.contatoDao = contatoDao;
    }

// ------------------------ INTERFACE METHODS ------------------------


// --------------------- Interface ContatoManager ---------------------

    @Override
    public void saveContato(Contato contato) {
        contatoDao.saveOrUpdate(contato);
    }

    @Override
    public List<Contato> getContatos() {
        return contatoDao.getAll();
    }

    public void removeContato(Contato contato) {
        contatoDao.removeContato(contato);
    }

    public List<Contato> getContatos(String filterOption, String filterValue)
    {
        if (filterOption.equals("Grupo"))
            return contatoDao.findByGrupo(filterValue);
        if (filterOption.equals("LetraInicial"))
            return contatoDao.findByLetraInicial(filterValue);

        return contatoDao.getAll();
    }
}
